package com.zz.parkingsystem.controller.admin;
import com.zz.parkingsystem.entity.RevenueCount;
import com.zz.parkingsystem.service.*;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
已经测完 这个方法里面的date时间应该从前端传过来  ？？？？？？？？？？？？
 */
@RestController
@RequestMapping("/admin/torderItem")
public class AdminOrderItemController {
    @Resource
    private OrderItemService orderItemService;
    @Resource
    private RefundService refundService;
    @Resource
    private ExceptionOrderService exceptionOrderService;
    @Resource
    private UserService userService;
    @Resource
    private RevenueCountService revenueCountService;
    @RequestMapping("/ordersum")       //这个方法里面的date时间应该从前端传过来  ？？？？？？？？？？？？
    public Result ordersum() throws ParseException {
        //查订单总数
        int i = orderItemService.getselOrderSum();
        System.out.println("查订单总数==================="+i);
        //总营收额
        double sum1= orderItemService.getselMoneySum();
        System.out.println("总营收额==================="+sum1);
        //查询退款订单数
        int i1 = refundService.getselRefundSum();
        System.out.println("查询退款订单数==================="+i1);
        //总退款金额
        double sum2= refundService.getselMoneySum();
        System.out.println("总退款金额==================="+sum2);
        //异常订单数量
        int i2 = exceptionOrderService.getunusualSum();
        System.out.println("异常订单数量==================="+i2);
        //异常订单金额
        double sum3 = exceptionOrderService.getunusualMoneySum();
        System.out.println("异常订单总金额==================="+sum3);
        //按照每天日期显示每日订单数 ???????????前端传入一个时间
        //将页面传来的时间string类型转换格式
        SimpleDateFormat sdf = new SimpleDateFormat(("yyyy-MM-dd"));
        java.util.Date time2=null;
        time2 = sdf.parse("2022-09-03");
        java.sql.Date date = new java.sql.Date(time2.getTime());
        int sumNumberBytime = orderItemService.getSumNumberBytime(date);
        System.out.println("当日时间对应的订单数量==================="+sumNumberBytime);
        //按照每天日期显示每日订单金额 ???????????前端传入一个时间
        double sumMoneyBytime = orderItemService.getSumMoneyBytime(date);
        System.out.println("当日时间对应的订单金额==================="+sumMoneyBytime);
        //按照每天日期显示每日退款订单数 ???????????前端传入一个时间
        int sumNumberBytime1 = refundService.getSumNumberBytime(date);
        System.out.println("按照每天日期显示每日退款订单数==================="+sumNumberBytime1);
        //按照每天日期显示每日退款金额
        double sumMoneyBytime1 = refundService.getSumMoneyBytime(date);
        System.out.println("按照每天日期显示每日退款金额==================="+sumMoneyBytime1);
        //用户增长按照传进来的时间查
        int i3 = userService.getselCountNumber(date);
        System.out.println("用户增长==================="+i3);
        //给营收统计表里面插入数据
        RevenueCount revenueCount = new RevenueCount();
        revenueCount.setCreatedTime(date);
        revenueCount.setRcOrdernum(sumNumberBytime);
        revenueCount.setRcAmount(new BigDecimal(String.valueOf(sumMoneyBytime)));
        revenueCount.setRcRefundAmount(new BigDecimal(String.valueOf(sumNumberBytime1)));
        revenueCount.setRcRefundAmount(new BigDecimal(String.valueOf(sumMoneyBytime1)));
        revenueCount.setRcUserGrowth(i3);
        int i4 = revenueCountService.insertSelective(revenueCount);
        //查所有revenueCount表,返回给前端界面
        List<RevenueCount> revenueCounts = revenueCountService.getselAll();
        return ResultGenerator.genSuccessResult(revenueCounts);
    }
}
